﻿using System;
using Config;

namespace Utils
{
    public class AdminUtils
    {
        /// <summary>
        /// Kiểm tra login chưa
        /// </summary>
        public static bool IsLogin
        {
            get
            {
                return !((CookieHelper.GetCookie(Constants.COOKIE_ADMIN_ID) == string.Empty)
                    || (CookieHelper.GetCookie(Constants.COOKIE_ADMIN_USERNAME) == string.Empty)
                    || (CookieHelper.GetCookie(Constants.COOKIE_ADMIN_FULL_NAME) == string.Empty));
            }
        }


        /// <summary>
        /// Lấy AdminID 
        /// </summary>
        public static int AdminID
        {
            get
            {
                try
                {
                    return Convert.ToInt32(CookieHelper.GetCookie(Constants.COOKIE_ADMIN_ID));
                }
                catch { }
                return -1;
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_ID, value.ToString());
            }
        }

        /// <summary>
        /// Lấy UserName của Admin
        /// </summary>
        public static string UserName
        {
            get
            {
                try
                {
                    return CookieHelper.GetCookie(Constants.COOKIE_ADMIN_USERNAME);
                }
                catch { }
                return "";
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_USERNAME, value);
            }
        }

        /// <summary>
        /// Lấy tên đầy đủ của Admin
        /// </summary>
        public static string FullName
        {
            get
            {
                return CookieHelper.GetCookie(Constants.COOKIE_ADMIN_FULL_NAME);
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_FULL_NAME, value);
            }
        }

        /// <summary>
        /// Lấy xâu quyền của Admin
        /// </summary>
        public static string Permission
        {
            get
            {
                return CookieHelper.GetCookie(Constants.COOKIE_ADMIN_PERMISSION);
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_PERMISSION, value);
            }
        }

        /// <summary>
        /// Lấy IPAdress
        /// </summary>
        public static string IpAddress
        {
            get
            {
                return CookieHelper.GetCookie(Constants.COOKIE_ADMIN_IP_ADDRESS);
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_IP_ADDRESS, value);
            }
        }

        public static int ServicesID
        {
            get
            {
                try
                {
                    return Convert.ToInt32(CookieHelper.GetCookie(Constants.COOKIE_ADMIN_SERVICES_ID));
                }
                catch { }
                return -1;
            }
            set
            {
                CookieHelper.SetCookie(Constants.COOKIE_ADMIN_SERVICES_ID, value.ToString());
            }
        }       

    }
}
